package com.szzg10.mina2.chapter9;

import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;

public class ImageServerHandler extends IoHandlerAdapter {

	@Override
	public void messageReceived(IoSession session, Object message)
			throws Exception {
		
		ImageRequest request = (ImageRequest)message;
		
		System.out.println("Width: " + request.getWidth());
		System.out.println("Height: " + request.getHeight());
		System.out.println("Number: " + request.getNumber());
		
		File file1 = new File(ImageServerHandler.class.getResource("").getPath() + "p1799081608.jpg");
		File file2 = new File(ImageServerHandler.class.getResource("").getPath() + "p1925977243.jpg");
		
		BufferedImage image1 = ImageIO.read(file1);
		BufferedImage image2 = ImageIO.read(file2);
		
		ImageResponse response = new ImageResponse(image1, image2);
		
		session.write(response);
	}
}
